package com.telnetnz.ticketdesk.action.base;

import org.apache.log4j.Logger;

import com.rockbb.common.simpleframe.config.SimpleConfig;
import com.rockbb.common.sso.acl.ACLBuilder;
import com.rockbb.common.sso.acl.ACLUtils;

public class BasicSessionPageAccAction extends BasicSessionPageLogAction
{
	private static Logger logger = Logger.getLogger(BasicSessionPageAccAction.class);

	public String intercepters()
	{
		String result = super.intercepters();

		if (result == null || result.equals(SUCCESS))
		{
			// Verify Permissions. Skip the permission check if it is a superuser
			if (!this.isSuperSession() 
					&& !ACLUtils.accVerify(getSessionUser().getPermissions(), getContext().getAccesses()))
			{
				return this.message_box(
						langRes.get("global.no-permission"), 
						langRes.get("global.no-permission-message"));
			}
		}
		return result;
	}

	public boolean isRole(String roleName)
	{
		Integer index = SimpleConfig.getRoleIndex(roleName);

		if (index != null)
			return ACLBuilder.IndexOf(getSessionUser().getPermissions(), index);
		else
			return false;
	}
}
